package bsc.war.populate;

import bsc.ejb.entity.Person;
import bsc.ejb.entity.PersonScoreDomain;
import bsc.ejb.entity.ScoreCard;
import bsc.ejb.entity.ScoreDomain;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author Miguel Angel
 */
public class VisionSettings extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");


        Person personDesigner = delegate.findPerson(1L);
        ScoreDomain scoreDomainDesigner = delegate.findScoreDomain(1L);

        Person person = delegate.findPerson(2L);



        //Se asocia persona al dominio

        PersonScoreDomain personScoreDomainDesigner = (PersonScoreDomain) Factory.getBean("PersonScoreDomain");
        personScoreDomainDesigner.setPerson(personDesigner);
        personScoreDomainDesigner.setScoreDomain(scoreDomainDesigner);
        personScoreDomainDesigner.setProfile(PersonScoreDomain.Profile.DESIGNER);
        personScoreDomainDesigner.setDefaultDomain(Boolean.TRUE);
        delegate.createPersonScoreDomain(personScoreDomainDesigner);

        PersonScoreDomain personScoreDomain = (PersonScoreDomain) Factory.getBean("PersonScoreDomain");
        personScoreDomain.setPerson(person);
        personScoreDomain.setScoreDomain(scoreDomainDesigner);
        personScoreDomain.setProfile(PersonScoreDomain.Profile.ADMINISTRATOR);
        personScoreDomain.setDefaultDomain(Boolean.TRUE);
        delegate.createPersonScoreDomain(personScoreDomain);



        return new ModelAndView("advancePopulate");
    }
}